package com.enation.app.javashop.api.client;

import com.enation.app.javashop.framework.database.DaoSupport;
import com.enation.app.javashop.model.shop.dos.ShopDO;
import com.enation.app.javashop.model.shop.dto.ShopBankDTO;
import com.enation.app.javashop.model.shop.vo.ShopVO;
import com.enation.app.javashop.service.shop.ShopManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * 店铺相关API
 * @author zhangjiping
 * @version v7.0.0
 * @since v7.0.0
 * 2018年3月30日 上午10:52:48
 */
@Api(description="店铺相关API")
@RestController
@RequestMapping("/client/shops")
@Validated
@ApiIgnore
public class ShopClientController {
	@Autowired
	private ShopManager shopManager;

	@ApiOperation(value	= "获取店铺详细",response = ShopVO.class)
	@GetMapping("/{shop_id}")
	@ApiImplicitParam(name = "shop_id" , value = "店铺id" , required = true , dataType = "int", paramType = "path")
	public ShopVO getShopVO(@ApiIgnore @PathVariable("shop_id") @NotNull(message="店铺id不能为空") Long shopId) {
		return shopManager.getShop(shopId);
	}

	@ApiOperation(value	= "通过会员获取店铺详细",response = ShopVO.class)
	@GetMapping("/member/{member_id}")
	@ApiImplicitParam(name = "member_id" , value = "会员id" , required = true , dataType = "int", paramType = "path")
	public ShopVO getShopVOByMember(@ApiIgnore @PathVariable("member_id") @NotNull(message="店铺id不能为空") Long memberId) {
		return shopManager.getShopByMemberId(memberId);
	}

	@ApiOperation(value	= "获取店铺银行信息佣金比例",response = ShopBankDTO.class)
	@GetMapping("/bank-info")
	public List<ShopBankDTO> getShopBankInfo() {
		return shopManager.listShopBankInfo();
	}

	@ApiOperation(value = "增加店铺收藏数")
	@PostMapping("/collection/{shop_id}")
	@ApiImplicitParam(name = "shop_id" , value = "店铺id" , required = true , dataType = "int", paramType = "path")
	public void addCollectNum(@ApiIgnore @PathVariable("shop_id") Long shopId){
		shopManager.addcollectNum(shopId);
	};

	@ApiOperation(value = "减少店铺收藏数")
	@PostMapping("/{shop_id}/collection")
	@ApiImplicitParam(name = "shop_id" , value = "店铺id" , required = true , dataType = "int", paramType = "path")
	public void reduceCollectNum(@ApiIgnore @PathVariable("shop_id") Long shopId){
		shopManager.reduceCollectNum(shopId);
	};

	@GetMapping("/calculate-shop-score")
	public void calculateShopScore() {
		shopManager.calculateShopScore();
	}

	@PostMapping("/{seller_id}/shop-goods-num")
	public void updateShopGoodsNum(@PathVariable("seller_id") Long sellerId, @RequestParam("seller_goods_count") Integer sellerGoodsCount){
		shopManager.updateShopGoodsNum(sellerId, sellerGoodsCount);
	}

	@GetMapping(value = "/shop-all-count")
	public int queryShopCount(){

		return shopManager.queryShopCount();
	}


	@GetMapping(value = "/range")
	public List<ShopDO> queryShopByRange(@RequestParam("page_no") Long i, @RequestParam("page_size")Long pageSize){

		return shopManager.queryShopByRange(i, pageSize);
	}


}

